<form class="layui-form" lay-filter="form" id="form" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">活动名称</label>
        <div class="layui-input-inline">
            <input type="text" name="title" lay-verify="required" lay-reqText="活动名称不能为空" autocomplete="off" class="layui-input">
        </div>
        <label class="layui-form-label">领取张数</label>
<div class="layui-input-inline">
    <input type="text" name="limit" lay-verify="number" value="0" lay-reqText="领取张数不能为空" autocomplete="off" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">0为不限制</div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">图片</label>
    <button type="button" class="layui-btn layui-btn-sm plupload_btn" id="up_image">选择图片</button>
    <script type="text/html" template>
        <a href="{{ d.params.image || '' }}" target="_blank">
            <img src="{{ d.params.image || '' }}" width="50" class="{{ d.params.image || 'layui-hide' }}">
        </a>
        <input type="hidden" value="{{ d.params.image || '' }}" name="image">
    </script>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">优惠类型</label>
    <div class="layui-input-inline">
        <input type="radio" name="type" lay-filter="type" value="1" title="满减" lay-verify="required" checked>
        <input type="radio" name="type" lay-filter="type" value="2" title="折扣" lay-verify="required">
    </div>
    <label class="layui-form-label">商家</label>
    <div class="layui-input-inline">
        <script type="text/html" template lay-url="{{ layui.setter.apiHost }}/seller/seller/select" lay-done="layui.form.render();">
            <select name="seller_id" lay-verify="required" lay-reqText="请选择商家">
                <option value=""></option>
                {{# layui.each(d.data, function(index, item){ }}
                <option value="{{ index }}" {{# if(index== d.params.seller_id){ }}selected{{# } }}>{{ item }}</option>
                {{# }); }}
            </select>
        </script>
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">起用金额</label>
    <div class="layui-input-inline">
        <input type="text" name="use_price" lay-verify="price" autocomplete="off" class="layui-input">
    </div>
    <label class="layui-form-label">优惠</label>
    <div class="layui-input-inline">
        <input type="text" name="amount" lay-verify="price" autocomplete="off" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux amount_prompt">元/折</div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">可用商品</label>
    <div class="layui-input-block">
        <input type="text" name="goods_id:in" autocomplete="off" class="layui-input" placeholder="默认全部商品，商品id之间用逗号隔开">
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">不可用商品</label>
    <div class="layui-input-block">
        <input type="text" name="goods_id:not_in" autocomplete="off" class="layui-input" placeholder="默认全部商品都可用，商品id之间用逗号隔开">
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">可用分类</label>
    <div class="layui-input-block">
        <input type="text" name="category_id:in" autocomplete="off" class="layui-input" placeholder="默认全部分类，分类id之间用逗号隔开">
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">不可用分类</label>
    <div class="layui-input-block">
        <input type="text" name="category_id:not_in" autocomplete="off" class="layui-input" placeholder="默认全部分类都可用，分类id之间用逗号隔开">
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">可用品牌</label>
    <div class="layui-input-block">
        <input type="text" name="brand_id:in" autocomplete="off" class="layui-input" placeholder="默认全部品牌，品牌id之间用逗号隔开">
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">不可用品牌</label>
    <div class="layui-input-block">
        <input type="text" name="brand_id:not_in" autocomplete="off" class="layui-input" placeholder="默认全部品牌都可用，品牌id之间用逗号隔开">
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">起止时间</label>
    <div class="layui-input-inline">
        <input type="text" name="start_at" id="start_at" lay-verify="required" lay-reqText="开始时间不能为空" autocomplete="off" class="layui-input" readonly>
    </div>
    <div class="layui-form-mid layui-word-aux">-</div>
    <div class="layui-input-inline">
        <input type="text" name="end_at" id="end_at" lay-verify="required" lay-reqText="结束时间不能为空" autocomplete="off" class="layui-input" readonly>
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">简介</label>
    <div class="layui-input-block">
        <textarea name="note" class="layui-textarea"></textarea>
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label"></label>
    <div class="layui-input-inline">
        <input type="hidden" name="id" value="">
        <input type="button" lay-submit lay-filter="form-submit" value="确认" class="layui-btn">
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</div>
</form>
<script type="text/html" template lay-done="layui.data.sendParams(d.params)"></script>
<script language="JavaScript" src="../../../layuiadmin/lib/plupload/plupload.full.min.js"></script>
<script language="JavaScript" src="../../../layuiadmin/lib/plupload/i18n/zh_CN.js"></script>
<script>
    layui.data.sendParams = function (params) {
        layui.use(['admin', 'form', 'plupload', 'laydate'], function () {
            var $ = layui.jquery,
                form = layui.form,
                laydate = layui.laydate,
                lay_id_prefix = 'market-coupons-add',//当前页id前缀
                plupload = layui.plupload;

            plupload.upload();//初始化图片上传

            //监听类型选择
            form.on('radio(' + lay_id_prefix + '-type)', function (data) {
                $('[name="amount"]').val('');
                select_type(data.value);
            });

            //更新规则填写
            function select_type(type_val) {
                var type_val = Number(type_val);
                switch (type_val) {
                    case 1:
                        prompt = '元(整数)';
                        break;
                    case 2:
                        prompt = '%，1-100';
                        break;
                }
                $('.amount_prompt').text(prompt);
            }

            //自定义验证规则
            form.verify({
                price: [
                    /(^-|[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/,
                    '请输入正确的金额,且最多两位小数!'
                ]
            });

            if (!params.id) {
                //日期
                laydate.render({
                    elem: '#start_at',
                    type: 'datetime'
                });
                laydate.render({
                    elem: '#end_at',
                    type: 'datetime'
                });
            }
        })
    }
</script>